package com.atguigu.tingshu.user.api;

import com.atguigu.tingshu.common.login.CustomLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.user.service.UserInfoService;
import com.atguigu.tingshu.vo.user.UserInfoVo;
import com.atguigu.tingshu.vo.user.UserPaidRecordVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "用户管理接口")
@RestController
@RequestMapping("api/user/userInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class UserInfoApiController {

	@Autowired
	private UserInfoService userInfoService;

	/**
	 * 根据用户Id获取用户信息
	 * @param userId
	 * @return
	 */
	@GetMapping("getUserInfoVo/{userId}")
	public Result<UserInfoVo> getUserInfoVo(@PathVariable Long userId) {
		// 获取用户信息
		UserInfoVo userInfoVo = userInfoService.getUserInfoVoByUserId(userId);
		return Result.ok(userInfoVo);
	}

	@CustomLogin(required = false)
	@Operation(summary = "查询用户是否收藏了该专辑")
	@GetMapping("/isSubscribe/{albumId}")
	public Result<Boolean> isSubscribe(@PathVariable("albumId") Long albumId) {
		Boolean result = userInfoService.isSubscribe(albumId);
		return Result.ok(result);
	}

	@Operation(summary = "修改用户vip过期时间")
	@PostMapping("updateExpiredVipStatus")
	public Result updateExpiredVipStatus(){
		this.userInfoService.updateExpiredVipStatus();
		return Result.ok();
	}

	@Operation(summary = "用户购买支付成功后，处理订单中的购买项")
	@PostMapping("/makeOrderPaidInfo")
	public Result makeOrderPaidInfo(@RequestBody UserPaidRecordVo userPaidRecordVo) {
		userInfoService.makeOrderPaidInfo(userPaidRecordVo);
		return Result.ok();
	}
}

